import { Sha256 } from "@aws-crypto/sha256-js";
import { HttpRequest } from "@smithy/protocol-http";
import { SignatureV4, SignatureV4CryptoInit, SignatureV4Init } from "@smithy/signature-v4";
import { credentials, region, service } from "./suite.fixture";
import { http } from "@kit.NetworkKit";

export const httpRequestOptions = {
  method: http.RequestMethod.POST,
  protocol: "https:",
  path: "/",
  headers: {},
  hostname: "foo.us-east-1.amazonaws.com",
};

export const mockHttpRequestOptions = (options: Record<string, Object>) => {
  return {
    ...httpRequestOptions,
    ...options
  }
}

export const minimalRequest = new HttpRequest({
  method: http.RequestMethod.POST,
  protocol: "https:",
  path: "/",
  headers: {
    host: "foo.us-east-1.amazonaws.com",
  },
  hostname: "foo.us-east-1.amazonaws.com",
});

export const mockMinimalRequest = (options: Record<string, Object>) => {
  return {
    ...minimalRequest,
    ...options
  }
}

export const minimalRequest2 = new HttpRequest({
  method: http.RequestMethod.POST,
  protocol: "https:",
  path: "/",
  hostname: "foo.us-east-1.amazonaws.com",
});

export const mockMinimalRequest2 = (options: Record<string, Object>) => {
  return {
    ...minimalRequest2,
    ...options
  }
}

export const suiteSigner = new SignatureV4({
  credentials,
  region,
  service,
  sha256: Sha256,
  applyChecksum: false,
});


export const getSignerInit = (): SignatureV4Init & SignatureV4CryptoInit => {
  return {
    service: "foo",
    region: "us-bar-1",
    sha256: Sha256,
    credentials: {
      accessKeyId: "foo",
      secretAccessKey: "bar",
    },
  };
}

export const getSignerInitWithToken = (): SignatureV4Init & SignatureV4CryptoInit => {
  return {
    service: "foo",
    region: "us-bar-1",
    sha256: Sha256,
    credentials: {
      accessKeyId: "foo",
      secretAccessKey: "bar",
      sessionToken:"baz"
    },
  }
}


export const getS3SignerInit = (): SignatureV4Init & SignatureV4CryptoInit => {
  return {
    service: "s3",
    region: "us-east-1",
    credentials: {
      accessKeyId: "AKIAIOSFODNN7EXAMPLE",
      secretAccessKey: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
    },
    sha256: Sha256,
  };
}
export const getServiceSignerInit = (): SignatureV4Init & SignatureV4CryptoInit => {
  return {
    service: "SERVICE",
    region: "REGION",
    credentials: {
      accessKeyId: "akid",
      secretAccessKey: "secret",
    },
    sha256: Sha256,
  };
}

